home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / hugearr.zip / HUGESAVE.C < prev    next >
C/C++ Source or Header  |  1992-04-02  |  2KB  |  60 lines

  1.  
  2. #define NOCOMM
  3. #include <windows.h>
  4.  
  5. #include "hugearr.h"
  6.  
  7. /* Store the contents of a huge array in an operating system file. */
  8. /* VBM: Declare Function VBHugeSave& Lib "hugearr.dll" Alias "VBHugeSave" (ByVal hArray%, ByVal NEl&, ByVal RecLen%, ByVal Fn$) */
  9. long FAR PASCAL
  10. VBHugeSave(int hArray, long nelements, int OutLen, LPSTR FileSpec)
  11.     {
  12.     int       hSaveFile;  /* handle to the save file */
  13.     HPBYTE    FmBegin;    /* pointer for first element */
  14.     HPBYTE    FmElem;     /* pointer to array element */
  15.     long      element;    /* element in the huge array */
  16.     PHUGEDESC pArray;     /* pointer to array descriptor */
  17.  
  18.     DecCheckHandle(hArray);
  19.  
  20.     pArray = (PHUGEDESC) LocalLock(hLocalMem) + hArray;
  21.  
  22.     CheckNotAllocYet(pArray);
  23.  
  24.     if (pArray -> ubound + 1 < nelements || nelements < 0)
  25.         {
  26.         /* subscript out of range */
  27.         LocalUnlock(hLocalMem);
  28.         return HA_SUBSCRIPT;
  29.         }
  30.  
  31.     /* Open the file */
  32.     hSaveFile = _lopen(FileSpec, OF_WRITE);
  33.     if (hSaveFile < 0)
  34.         {
  35.         LocalUnlock(hLocalMem);
  36.         return HA_FILEOPENERROR;
  37.         }
  38.  
  39.     /* calculate pointer to element */
  40.     FmBegin = (HPBYTE) GlobalLock(pArray -> handle);
  41.  
  42.     for(element = 0L; element < nelements; element++)
  43.         {
  44.         FmElem = FmBegin + HugeElementOffset(element, pArray->perseg, pArray->recsize);
  45.  
  46.         /* Write out the record */
  47.         if(_lwrite(hSaveFile, FmElem, OutLen) < 0)
  48.             {
  49.             element = HA_FILEWRITEERROR;
  50.             break;
  51.             }
  52.         }
  53.  
  54.     /* Wrap up and return */
  55.     GlobalUnlock(pArray -> handle);
  56.     LocalUnlock(hLocalMem);
  57.     _lclose(hSaveFile);
  58.     return element;
  59.     }
  60.